package com.zuoyeben123.testzybhtml.protocol;

public abstract class TpPackage implements Package {
	
	public TpPackage() {
	}
	
	protected void init() {
		data = initData();
	}

	private byte[] data; //元数据
	
	@Override
	public byte[] encode() {
		if(data != null) {
			int len = data.length;
			byte[] lenbytes = new NetInteger(len).toBytes();
			byte[] totalData = new byte[len + 4];
			System.arraycopy(lenbytes, 0, totalData, 0, lenbytes.length);
			System.arraycopy(data, 0, totalData, 4, data.length);
			return totalData;
		} else {
			return null;
		}
	}

	@Override
	public byte[] decode() {
		// TODO Auto-generated method stub
		return null;
	}
	
	abstract byte[] initData();

}
